$(document).ready(function () {

    $("form [name=userNum]").blur( function (){

    });

    // 展现检测结果
    warnCk = function (group,flag) {
        // console.log("warnCK " + flag);
        if(flag==true) {
            // console.log("bianlv");
            // console.log(group + " .help-block");
            // console.log($(group + " .help-block"));
            $(group).addClass("has-success") , $(group).removeClass("has-warning");
            $(group + " .help-block")[0].style.display = 'none';
        } else {
            $(group).addClass("has-warning") , $(group).removeClass("has-success");
            // console.log(group);
            // console.log($(group + " .help-block"));
            $(group + " .help-block")[0].style.display = 'inline';
        }
    }

    formCk = function (name,val) {
        var pattern = /^[0-9]{12}$/;
        str = val;

        if(name=="userNum")     pattern = /^[0-9]{12}$/;                // 12位数字
        if(name=="userName")    pattern = /^[\u4E00-\u9FA5A-Za-z0-9_]{1,10}$/;   // 1-7汉字数字字母下划线
        if(name=="userPwd")     pattern = /^[A-Za-z0-9]{6,20}$/;                // 6-20字母，数字
        if(name=="userAbl")     pattern = pattern = /^[0-9]{6}$/;           // 6位数字
        console.log(pattern.test(str));
        if(""!= pattern.test(str)) {
            warnCk("#" + name + "1" ,true);
            return true;
        } else {
            warnCk("#" + name + "1" ,false);
            return false;
            // console.log($(".has-success"));
        }
    }
    // $("[name=userNum]").blur( formCk ("userNum", $(this).val()));
    $("[name=userNum]").blur( function () {
        if(!formCk ("userNum", $(this).val())){
            $("#userNum1 small").text("格式不正确(12位有效数字)");
            return;
        }
        console.log("账号检测函数被调用")
        $.ajax({
            url: "../servletDemo3",
            data: {
                action: "userExactCheck",
                userNum: $("form [name=userNum]").val(),
            },
            async: false,
            type: "POST",
            success: function (msg) {
                // alert(msg);
                console.log(msg);
                if(msg==true){
                    $("#userNum1 small").text("该账户已注册");
                    warnCk("#userNum1",false);

                }
            },
            dataType: "json"
        });
    });
    $("[name=userName]").blur( function () {
        formCk ("userName", $(this).val());
    });
    $("[name=userPwd]").blur( function () {
        formCk ("userPwd", $(this).val());
    });
    $("[name=userPwdrp]").blur( function () {
        // console.log("cccasd");
        if($(this).val()!=$("[name=userPwd]").val())    warnCk("#userPwdr1",false);
        else warnCk("#userPwdr1",true);
    });
    $("[name=userAbl]").blur( function () {
        if($(this).val()=="")   warnCk("#userAbl1",true);
        else    formCk ("userAbl", $(this).val())
    });
    $("[name=userBir]").blur( function () {
        if($(this).val()=="")   warnCk("#userBir1",false);
        else warnCk("#userBir1",true);
        console.log($(".form-check-input"));
    });
    $(".form-check-input").change( function (){
        if($(this).checked == false)   warnCk("#readCk1",false);
        else warnCk("#readCk1",true);
    });

    regCk = function () {
        console.log($(".has-success"));
        if($(".form-check-input").is(':checked'))   {
            console.log("cacc");
            warnCk("#readCk1",true);
        } else {
            console.log("ccc");
            warnCk("#readCk1",false)
            alert("请补充正确的用户信息");
            return false;
        }
        if($(".has-success").length == 7)   return true;
        else {
            alert("请补充正确的用户信息");
            return false;
        }
    }

});